Requires Scripting PRO
The BluetoothCentralManager namespace provides core functionality for managing Bluetooth Low Energy (BLE) operations as a central device. It supports scanning, connecting, disconnecting, and retrieving known or connected peripherals. This API is ideal for building custom Bluetooth workflows, interacting with smart devices, wearables, and IoT peripherals.
isScanning: Promise<boolean>Returns whether the central manager is currently scanning for peripherals.
Type: Promise<boolean>
Example:
startScan(onDiscoverPeripheral, options?): Promise<void>Starts scanning for BLE peripherals. The scan continues until you call
stopScan(). The callback will be triggered every time a peripheral is discovered.
onDiscoverPeripheral: (peripheral, advertisementData, rssi) => void
Callback triggered on discovery.
Arguments:
peripheral: A BluetoothPeripheral objectadvertisementData: A BluetoothAdvertisementData objectrssi: Signal strength in dBmoptions?: { services?: string[]; allowDuplicates?: boolean; solicitedServiceUUIDs?: string[] }
services: An array of UUID strings to filter devices by servicesallowDuplicates: If true, reports duplicates; if false (default), filters out repeated discoveriessolicitedServiceUUIDs: An array of UUID strings to filter devices by solicited servicesWhen using BluetoothCentralManager.startScan() to scan for Bluetooth peripherals, each discovered device includes an advertisementData object. This object contains key metadata extracted from the peripheral's BLE advertisement packets. It can help identify, filter, or categorize devices before establishing a connection.
| Field Name | Type | Description |
|---|---|---|
localName |
string (optional) |
The local name advertised by the peripheral, if available. Useful for display. |
txPowerLevel |
number (optional) |
Transmit power level in dBm. Combined with RSSI, it can be used for distance estimation. |
manufacturerData |
Data (optional) |
Manufacturer-specific binary data. Often used to encode model or serial information. |
serviceData |
Record<string, Data> (optional) |
Service-specific data mapped by UUID. Each value is a Data object. |
serviceUUIDs |
string[] (optional) |
List of service UUIDs the peripheral is advertising. Indicates supported capabilities. |
overflowServiceUUIDs |
string[] (optional) |
Additional service UUIDs not included in serviceUUIDs due to size limits. |
isConnectable |
boolean (optional) |
Indicates whether the peripheral accepts connections. Helps filter broadcast-only devices. |
solicitedServiceUUIDs |
string[] (optional) |
UUIDs of services that the peripheral is requesting from central devices. |
localName, serviceUUIDs, or isConnectablemanufacturerDatatxPowerLevel + RSSIsolicitedServiceUUIDsmanufacturerData and serviceData are raw Data objects and must be parsed using manufacturer-specific formats.serviceUUIDs represent only advertised services. To get the full list of available services, call peripheral.discoverServices() after connecting.Promise<void>stopScan(): Promise<void>Stops an ongoing scan.
Promise<void>retrievePeripherals(ids: string[]): Promise<BluetoothPeripheral[]>Retrieves known peripherals by their identifiers.
ids: An array of peripheral UUID stringsPromise<BluetoothPeripheral[]>retrieveConnectedPeripherals(serviceUUIDs: string[]): Promise<BluetoothPeripheral[]>Retrieves currently connected peripherals that provide at least one of the specified services.
serviceUUIDs: An array of service UUID stringsPromise<BluetoothPeripheral[]>connect(peripheral, options?): Promise<void>Establishes a connection to the specified peripheral.
peripheral: A BluetoothPeripheral object to connect to
options?:
startDelay?: number – Delay in seconds before connectingenableTransportBridging?: boolean – Enables transport bridging (advanced)requiresANCS?: boolean – Whether Apple Notification Center Service is requiredenableAutoReconnect?: boolean – Whether to auto-reconnect if disconnectednotifyOnConnection?: boolean - Whether to notify when the connection is establishednotifyOnDisconnection?: boolean - Whether to notify when the connection is disconnectednotifyOnNotification?: boolean - Whether to notify when a notification is receivedPromise<void>disconnect(peripheral): Promise<void>Disconnects from the specified peripheral. This is a non-blocking operation.
peripheral: A BluetoothPeripheral objectPromise<void>onDisconnected will be triggered.stopScan() when scanning is no longer needed to save battery and reduce system load.discoverServices() followed by discoverCharacteristics() before reading or writing data.